/* ========================= */
/*		protoload			 */

Element.implement({
	// the script to wait this amount of msecs until it shows the loading element
	HooMaskTimeUntilShow: 250,
	
	// opacity of loading element
	HooMaskOpacity: 0.8,

	// Start waiting status - show loading element
	HooMaskSet: function(className, timeUntilShow) {
		element = this;
		if (className == undefined)
			className = 'waiting';
		if (timeUntilShow == undefined)
			timeUntilShow = this.maskTimeUntilShow;
		
		element._waiting = true;
		if (!element._loading) {
			var e = new Element('div');
			(element.offsetParent || document.body).appendChild(element._loading = e);
			e.setStyle('position', 'absolute');
			try {e.style.opacity = this.HooMaskOpacity;} catch(e) {}
			try {e.style.MozOpacity = HooMaskOpacity;} catch(e) {}
			try {e.style.filter = 'alpha(opacity='+Math.round(HooMaskOpacity * 100)+')';} catch(e) {}
			//try {e.style.KhtmlOpacity = HooMaskOpacity;} catch(e) {}
			/*var zIndex = 0;
			if (window.UI)
				if (UI.zIndex)
					zIndex = ++UI.zIndex;
			if (!zIndex)
				zIndex = ++Protoload._zIndex;
			e.style.zIndex = zIndex;*/
		}
		element._loading.addClass(className);
		window.setTimeout((function() {
		    if (this._waiting) {
			var coords = this.getCoordinates();
			/*var left = this.offsetLeft,
				    top = this.offsetTop,
				    width = this.offsetWidth,
				    height = this.offsetHeight,
				    l = this._loading;*/
			var size = this.getScroll();
			this._loading.setStyles({
			    left: (coords.left + size.x)+'px',
			    top: (coords.top + size.y)+'px',
			    width: coords.width+'px',
			    height: coords.height+'px',
			    display: 'inline'
			});
		    }
		}).bind(element), this.HooMaskTimeUntilShow);
	},
	
	// Stop waiting status - hide loading element
	HooMaskRemove: function() {
		element = this;
		if (element._waiting) {
			element._waiting = false;
			element._loading.parentNode.removeChild(element._loading);
			element._loading = null;
		}
	}/*,
	
	_zIndex: 1000000*/
});